package cn.com.gome.sn.web.common;

import java.io.Serializable;
/**
 * 分页信息
 *
 */
public class PageInfo implements Serializable{
	
	private static final long serialVersionUID = 2939484825402232807L;
	
	private int startIndex=1;//当前页
	private int pageSize=10;//每页个数
	private int pageNum;
	private int totalPage;//总页数
	private int totalCount;//记录数
	
	private String pageFlag;
	public String getPageFlag() {
		return pageFlag;
	}

	public void setPageFlag(String pageFlag) {
		this.pageFlag = pageFlag;
	}
	
	public int getStartIndex() {
		return startIndex;
	}
	public void setStartIndex(int startIndex) {
		this.startIndex = startIndex;
	}
	public int getPageNum() {
		return pageNum;
	}
	public void setPageNum(int pageNum) {
		this.pageNum = pageNum;
	}
	public int getTotalPage() {
		return totalPage;
	}
	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}
	public int getTotalCount() {
		return totalCount;
	}
	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	 //初始化分页相关信息  
    public static void setPageInfo(PageInfo pageObj , Integer pageNum, Integer pageSize, Integer totalCount){  
        if(null==pageSize || pageSize<=0){
            pageSize = 10;  
        }  
        if(pageSize>50){  
            pageSize = 50;  
        }
        if(totalCount==null){
        	totalCount = 0;
        }
        Integer totalPage = (totalCount+pageSize-1)/pageSize;  
        if(null==pageNum){  
            pageNum = 1;  
        }else if(pageNum>totalPage){  
            pageNum = totalPage;  
        }  
        pageObj.setStartIndex(getStartIndex(pageNum, pageSize));
        pageObj.setPageNum(pageNum);
        pageObj.setTotalPage(totalPage);
        pageObj.setPageSize(pageSize);
        pageObj.setTotalCount(totalCount);
    }
    
    public static Integer getStartIndex(Integer pageNum, Integer pageSize){  
        Integer res = 0;  
        if(pageNum>0){  
            res = (pageNum-1)*pageSize;  
        }  
        return res;  
    } 
}
